package weaver.interfaces.dfhj.duss.action;

import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.dfhj.duss.util.CalUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2021-10-28
 * @Description: 工程采购/施工合同审批流程
 * @ModifyLog:
 **/
/*
 *@Description: 工程采购/施工合同审批流程提交后更新该所属项目szxm下、合同类型htlx1为钢材的明细表设备明细数量sly的总额
 *@Param:
 *@return:
 *@Author: Dusongsong
 *@Date: 2020/12/10
 */
public class WeaUpateSlToGcssdbbAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        baseBean.writeLog( "-----WeaUpateSlToGcssdbbAction-----" );
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        String gcs_tableName = "uf_gcssdbb";//平台预留和实际采购对比表
        try {
            rs.executeQuery( "select szxm from " + tablename + " where requestid=?", requestid );
            rs.next();
            String szxm = Util.null2String( rs.getString( "szxm" ) );//所属项目
            rs.executeQuery( "select sum(t1.sly) from " + tablename + " t left join " +
                    tablename + "_dt1 t1 on t.id=t1.mainid where t.szxm=? and t.htlx1 = 5", szxm );
            rs.next();
            String sjcgl =  CalUtil.isZero(Util.null2String( rs.getString( 1 )),2);//实际采购量
            rs.executeUpdate( "update " + gcs_tableName + " set sjcgl=? where xmbh=?",sjcgl,szxm);
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
